<template>
  <div class="mt-2 items-end text-right">
    <div v-if="props.formType == 'text'">
      <el-form-item :label="props.label">
        <el-input v-model="CurrInputValue" :disable="props.disEnable" outlined type="text"></el-input>
      </el-form-item>
    </div>
    <div v-if="props.formType == 'textarea'">
      <el-form-item :label="props.label">
        <el-input v-model="CurrInputValue" :disable="props.disEnable" outlined type="textarea"></el-input>
      </el-form-item>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, ref, watch } from "vue";
import { requestSysCommonGetConfigs } from "@/api/modules/sysCommon";
import { ResultData } from "@/api/interface";

const props = defineProps({
  configKey: {
    type: String,
    default: ""
  },
  label: {
    type: String,
    default: "请输入"
  },
  formType: {
    type: String,
    default: "text"
  },
  disEnable: {
    type: Boolean,
    default: false
  }
});

//调接口获取配置值
onMounted(async () => {
  requestSysCommonGetConfigs([props.configKey]).then((res: ResultData) => {
    if (res.data[props.configKey]) {
      CurrInputValue.value = res.data[props.configKey];
    }
    //console.log(res, " ---res");
  });
});

//值改变时通知父组件
let CurrInputValue = ref("");
const emits = defineEmits(["valChange"]);
watch(CurrInputValue, (nval: string, oval: string) => {
  emits("valChange", props.configKey, nval);
});
</script>

<style scoped></style>
